﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Common.Data.Converters="clr-namespace:Imagin.Common.Data.Converters;assembly=Imagin.Common"
    xmlns:Common.Extensions="clr-namespace:Imagin.Common.Extensions;assembly=Imagin.Common"
    xmlns:Controls.Common="http://imagin.tech/imagin/controls/common"
    xmlns:Controls.Extended="clr-namespace:Imagin.Controls.Extended;assembly=Imagin.Controls.Extended">
    <Common.Data.Converters:IntToBooleanConverter x:Key="IntToBooleanConverter"/>
    <Common.Data.Converters:ObjectToTypeConverter x:Key="ObjectToTypeConverter"/>

    <Style x:Key="{x:Type TreeView}" TargetType="{x:Type TreeView}">
        <Setter Property="Background" Value="{DynamicResource Brush.TreeView.Background}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource Brush.TreeView.Border}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Foreground" Value="{DynamicResource Brush.Text}"/>
        <Setter Property="Padding" Value="5"/>
        <Setter Property="Controls.Common:TreeViewExtensions.SelectionMode" Value="Single"/>
        <Setter Property="VirtualizingPanel.IsVirtualizing" Value="True"/>
        <Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling"/>
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Opacity" Value="0.6" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="{x:Type Controls.Common:TreeViewExt}" TargetType="{x:Type Controls.Common:TreeViewExt}" BasedOn="{StaticResource {x:Type TreeView}}">
        <Setter Property="ColumnHeaderHeight" Value="30"/>
    </Style>

    <Style x:Key="{x:Type Controls.Common:TreeViewColumnHeader}" TargetType="{x:Type Controls.Common:TreeViewColumnHeader}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="{DynamicResource Brush.DataGridColumnHeader.Border}" />
        <Setter Property="BorderThickness" Value="1,0,1,1" />
        <Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
        <Setter Property="Padding" Value="5,7"/>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.MouseOver.Background}" />
                <Setter Property="BorderBrush" Value="{DynamicResource Brush.DataGridColumnHeader.MouseOver.Border}" />
                <Setter Property="Foreground" Value="{DynamicResource Brush.DataGridColumnHeader.MouseOver.Foreground}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.Pressed.Background}" />
                <Setter Property="BorderBrush" Value="{DynamicResource Brush.DataGridColumnHeader.Pressed.Border}" />
                <Setter Property="Foreground" Value="{DynamicResource Brush.DataGridColumnHeader.Pressed.Foreground}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="{x:Type Controls.Common:TreeViewColumnHeadersPresenter}" TargetType="{x:Type Controls.Common:TreeViewColumnHeadersPresenter}">
        <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.Background}"/>
    </Style>

    <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="TextBlock.Foreground" Value="{DynamicResource Brush.Text}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="IsExpanded" Value="False" />
        <Setter Property="Controls.Common:TreeViewItemExtensions.IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
        <Setter Property="Controls.Common:TreeViewItemExtensions.ExpandOnClick" Value="True" />
        <Setter Property="Controls.Common:TreeViewItemExtensions.CollapseSiblingsOnClick" Value="True" />
        <Setter Property="Controls.Common:TreeViewItemExtensions.SelectOnRightClick" Value="True" />
        <Setter Property="Opacity" Value="0" />
        <Setter Property="Padding" Value="10,5" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TreeViewItem">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="15" Width="15"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        
                        <ToggleButton 
                            x:Name="PART_Expander" 
                            Background="{DynamicResource Brush.TreeViewItem.ToggleButton.Empty.Fill}" 
                            BorderBrush="{DynamicResource Brush.TreeViewItem.ToggleButton.Empty.Stroke}"
                            BorderThickness="1" 
                            Width="12" 
                            Height="12" 
                            Focusable="False" 
                            IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" 
                            ClickMode="Press">
                            <ToggleButton.Style>
                                <Style TargetType="{x:Type ToggleButton}">
                                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                                    <Setter Property="VerticalContentAlignment" Value="Center" />
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                <Ellipse 
                                                    Fill="{TemplateBinding Background}"
                                                    Stroke="{TemplateBinding BorderBrush}"
                                                    StrokeThickness="{TemplateBinding BorderThickness}"
                                                    Width="{TemplateBinding Width}" 
                                                    Height="{TemplateBinding Height}" 
                                                    SnapsToDevicePixels="True"/>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ToggleButton.Style>
                        </ToggleButton>
                        <Border 
                            Grid.Column="1" 
                            Grid.ColumnSpan="2" 
                            Name="PART_Border" 
                            Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Padding="{TemplateBinding Padding}" 
                            SnapsToDevicePixels="True">
                            <Controls.Common:TreeViewRowHeader
                                x:Name="PART_Header"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
                        </Border>
                        <ItemsPresenter 
                            Grid.Row="1" 
                            Grid.Column="1" 
                            Grid.ColumnSpan="2"
                            x:Name="ItemsHost"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding Mode=OneWay, Converter={StaticResource ObjectToTypeConverter}}" Value="{x:Type Controls.Common:Line}">
                            <Setter TargetName="PART_Expander" Property="Visibility" Value="Collapsed"/>
                            <Setter Property="IsEnabled" Value="False"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Mode=OneWay, Converter={StaticResource ObjectToTypeConverter}}" Value="{x:Type Separator}">
                            <Setter TargetName="PART_Expander" Property="Visibility" Value="Collapsed"/>
                            <Setter Property="IsEnabled" Value="False"/>
                        </DataTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasItems" Value="True"/>
                                <Condition Property="IsExpanded" Value="True"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ItemsHost" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="PART_Expander" Property="Background" Value="{DynamicResource Brush.TreeViewItem.ToggleButton.Filled.Checked.Fill}"/>
                            <Setter TargetName="PART_Expander" Property="BorderBrush" Value="{DynamicResource Brush.TreeViewItem.ToggleButton.Filled.Checked.Stroke}"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasItems" Value="True"/>
                                <Condition Property="IsExpanded" Value="False"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="PART_Expander" Property="Background" Value="{DynamicResource Brush.TreeViewItem.ToggleButton.Filled.Fill}"/>
                            <Setter TargetName="PART_Expander" Property="BorderBrush" Value="{DynamicResource Brush.TreeViewItem.ToggleButton.Filled.Stroke}"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasItems" Value="False"/>
                                <Condition Property="IsExpanded" Value="True"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ItemsHost" Property="Visibility" Value="Visible"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasItems" Value="False"/>
                                <Condition Property="IsExpanded" Value="False"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="Controls.Common:TreeViewItemExtensions.IsSelected" Value="False"/>
                                <Condition SourceName="PART_Border" Property="IsMouseOver" Value="True"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource Brush.TreeViewItem.MouseOver.Background}"/>
                            <Setter Property="TextBlock.Foreground" Value="{DynamicResource Brush.TreeViewItem.MouseOver.Foreground}"/>
                            <Setter TargetName="PART_Expander" Property="Background" Value="{DynamicResource Brush.TreeViewItem.MouseOver.Background}"/>
                            <Setter TargetName="PART_Expander" Property="BorderBrush" Value="{DynamicResource Brush.TreeViewItem.MouseOver.ToggleButton.Stroke}"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="Controls.Common:TreeViewItemExtensions.IsSelected" Value="True"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Expander" Property="Background" Value="{DynamicResource Brush.TreeViewItem.Selected.Background}"/>
                            <Setter TargetName="PART_Expander" Property="BorderBrush" Value="{DynamicResource Brush.TreeViewItem.Selected.Background}"/>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Controls.Common:ControlExtensions.IsDraggingOver" Value="True">
                <Setter Property="BorderBrush" Value="{DynamicResource Brush.DropTarget.Border}" />
            </Trigger>
            <Trigger Property="Controls.Common:TreeViewItemExtensions.IsSelected" Value="True">
                <Setter Property="Background" Value="{DynamicResource Brush.TreeViewItem.Selected.Background}"/>
                <Setter Property="TextBlock.Foreground" Value="{DynamicResource Brush.TreeViewItem.Selected.Foreground}"/>
            </Trigger>
            <EventTrigger RoutedEvent="TreeViewItem.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1.0" Duration="0:0:0.5" AccelerationRatio="0.4" DecelerationRatio="0.4"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="{x:Type Controls.Extended:TabbedTree}" TargetType="{x:Type Controls.Extended:TabbedTree}">
        <Setter Property="ColumnResizeMode" Value="ResizeWithPreview"/>
        <Setter Property="ContentBorderBrush" Value="{DynamicResource Brush.TabControl.Border}"/>
        <Setter Property="ContentBorderThickness" Value="1"/>
        <Setter Property="ContentHeaderVisibility" Value="Visible"/>
        <Setter Property="ContentPadding" Value="10"/>
        <Setter Property="ContentWidth" Value="70*"/>
        <Setter Property="MenuWidth" Value="30*"/>
        <Setter Property="SplitterWidth" Value="4"/>
        <Setter Property="ContentHeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Label 
                        Content="{Binding Mode=OneWay}"
                        Margin="0,0,0,10"
                        Padding="0,0,0,7"
                        Style="{DynamicResource H1}"/>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type Controls.Extended:SystemTreeView}" TargetType="{x:Type Controls.Extended:SystemTreeView}" BasedOn="{StaticResource {x:Type Controls.Common:TreeViewExt}}">
    </Style>
</ResourceDictionary>